using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks
{
    [TaskDescription("Check whether the enemy is in the range.")]
    [TaskCategory("Custom")]
    public class ConditionEnemyInAttackRange : Conditional
    {
        [Tooltip("The enemy to attack")]
        public Transform enemy;
        [Tooltip("The range distance")]
        public float distance = 0f;

        public override TaskStatus OnUpdate()
        {
            if (Blackboard.isEnemyDead) return TaskStatus.Failure;

            if (Vector3.Distance(enemy.position, transform.position) <= distance)
            {
                return TaskStatus.Success;
            }
            return TaskStatus.Failure;
        }
    }
}